package com.atguigu.gmall.weball.controller;

import com.atguigu.gamll.feign.search.SearchFeignClient;
import com.atguigu.gmall.search.vo.SearchParamVo;
import com.atguigu.gmall.search.vo.SearchRespVo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;

/**
 * @author lhh
 * @ClassName SearchController
 * @date 2022 2022/12/12
 */
@Controller
public class SearchController {

    @Resource
    SearchFeignClient searchFeignClient;

    @GetMapping("/list.html")
    public String search(SearchParamVo paramVo, Model model) {

        SearchRespVo searchRespVo = searchFeignClient.search(paramVo).getData();
        //检索参数;SearchParamVo
        model.addAttribute("searchParam", paramVo);
        //品牌面包屑;  字符串
        model.addAttribute("trademarkParam", searchRespVo.getTrademarkParam());

        //平台属性面包屑; 集合；[{attrName、attrValue、attrId}]
        model.addAttribute("propsParamList", searchRespVo.getPropsParamList());

        //品牌列表： 集合 [{tmId、tmName、tmLogoUrl}]
        model.addAttribute("trademarkList", searchRespVo.getTrademarkList());

        //属性列表： 集合 [{attrName、attrValueList(字符串集合)、attrId}]
        model.addAttribute("attrsList", searchRespVo.getAttrsList());

        //url参数
        model.addAttribute("urlParam", searchRespVo.getUrlParam());

        //排序信息（type、sort）
        model.addAttribute("orderMap", searchRespVo.getOrderMap());

        //商品列表 集合[{每个商品信息}]
        model.addAttribute("goodsList", searchRespVo.getGoodsList());

        //页码
        model.addAttribute("pageNo", searchRespVo.getPageNo());

        //总页码
        model.addAttribute("totalPages", searchRespVo.getTotalPages());

        return "list/index";
    }
}
